/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs575.dbentities;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author bms
 */
@Entity
@Table(name = "group_member", catalog = "tasks_management", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "GroupMember.findAll", query = "SELECT g FROM GroupMember g"),
    @NamedQuery(name = "GroupMember.findByGroupId", query = "SELECT g FROM GroupMember g WHERE g.groupMemberPK.groupId = :groupId"),
    @NamedQuery(name = "GroupMember.findByUserId", query = "SELECT g FROM GroupMember g WHERE g.groupMemberPK.userId = :userId")})
public class GroupMember  implements Serializable, IGroupRole {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected GroupMemberPK groupMemberPK;
    @JoinColumn(name = "role_id", referencedColumnName = "role_id")
    @ManyToOne(fetch = FetchType.LAZY)
    private Role role;
    @JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private User user;
    @JoinColumn(name = "group_id", referencedColumnName = "group_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private GroupEx groupEx;

    public GroupMember() {
    }

    public GroupMember(GroupMemberPK groupMemberPK) {
        this.groupMemberPK = groupMemberPK;
    }

    public GroupMember(int groupId, int userId) {
        this.groupMemberPK = new GroupMemberPK(groupId, userId);
    }

    public GroupMemberPK getGroupMemberPK() {
        return groupMemberPK;
    }
    @Override
    public GroupEx getGroupEx() {
        return groupEx;
    }

    @Override
    public Role getRole() {
        return role;
    }

    @Override
    public User getUser() {
        return user;
    }
    
    public void setGroupMemberPK(GroupMemberPK groupMemberPK) {
        this.groupMemberPK = groupMemberPK;
    }

    public void setRole(Role roleId) {
        this.role = roleId;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setGroupEx(GroupEx groupEx) {
        this.groupEx = groupEx;
    }
    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (groupMemberPK != null ? groupMemberPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof GroupMember)) {
            return false;
        }
        GroupMember other = (GroupMember) object;
        if ((this.groupMemberPK == null && other.groupMemberPK != null) || (this.groupMemberPK != null && !this.groupMemberPK.equals(other.groupMemberPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cs575.dbentities.GroupMember[ groupMemberPK=" + groupMemberPK + " ]";
    }
    
}
